﻿using Common.Lib.Dto;
using Common.Lib.Parameter;
using Common.Lib.Service;
using Microsoft.AspNetCore.Mvc;
using Server.Todo.Service;

namespace Server.Todo.Controllers
{
    /// <summary>
    /// 备忘录
    /// </summary>
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class MemoController:ControllerBase
    {
        private readonly IMemoService memoService;

        /// <summary>
        /// 备忘录
        /// </summary>
        public MemoController(IMemoService memoService)
        {
            this.memoService = memoService;
        }

        [HttpGet]
        public async Task<ApiResponse> Get(int id)
        {
            return await memoService.GetSingleAsync(id);
        }


        [HttpGet]
        public async Task<ApiResponse> GetAll([FromQuery] QueryParameter queryParameter)
        {
            return await memoService.GetAllAsync(queryParameter);
        }


        [HttpPost]
        public async Task<ApiResponse> Add([FromBody] MemoDto model)
        {
            return await memoService.AddAsync(model);
        }


        [HttpPost]
        public async Task<ApiResponse> Update([FromBody] MemoDto model)
        {
            return await memoService.UpdateAsync(model);
        }

        [HttpGet]
        public async Task<ApiResponse> Delete(int id)
        {
            return await memoService.DeleteAsync(id);
        }
    }
}
